const Constant = require("./constant.js");
const VodafoneGhsPageTag = require("./vodafoneGhsPageTag.js");
const RunDefine = require("./baseRunDefine.js");
const SmsUtil = require("./baseSmsUtil.js");
const BaseStringUtil = require("./baseStringUtil.js");

// 一次查询所有标记页状态
const doCheckPageStatus = () => {
    // 状态集合
    let pageStatus = {
        isLoginPage: false,
        isLoginPinPage: false,
        isServicesPage: false,
        isHomePage: false,
        isBillCheckConfirmPage: false,
        isBillListPage: false,
        isSendMoneyPage: false,
        isSendMoneyAccountInputPage: false,
        isSendMoneyConfirmPage: false,
        isSendMoneySuccessPage: false,
        isSendMoneyFailPage: false,
    }

    // 查找所有节点
    let textList = className("TextView").find();
    let editList = className("EditText").find();

    // 判断是否为登录页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为登录页-textList ", textList.length)
    let loginCon1 = false;
    let loginCon2 = false;
    let loginCon3 = false;
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.loginPageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是登录页")
            loginCon1 = true;
            break;
        }
        if (curText.indexOf(VodafoneGhsPageTag.loginPageTag4) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是登录页")
            loginCon3 = true;
            break;
        }
    }
    // console.log(Constant.UI_SDK_VERSION + "判断是否为登录页-editList ", editList.length)
    for (let index = 0; index < editList.length; index++) {
        let tv = editList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(VodafoneGhsPageTag.loginPageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是登录页")
            loginCon2 = true;
            break;
        }
    }
    if ((loginCon1 && loginCon3) || loginCon2) {
        pageStatus.isLoginPage = true;
    }

    // 判断是否为pin页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为PIN页-textList ", textList.length)
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.pinPageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是登录-pin页");
            pageStatus.isLoginPinPage = true;
            break;
        }
    }

    let servicesCon1 = false;
    let servicesCon2 = false;
    let servicesCon3 = false;
    let servicesCon4 = false;
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.servicesPageTag1) !== -1) {
            servicesCon1 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.servicesPageTag2) !== -1) {
            servicesCon2 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.servicesPageTag3) !== -1) {
            servicesCon3 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.servicesPageTag4) !== -1) {
            servicesCon4 = true
        }

        if (servicesCon1 && servicesCon2 && servicesCon3 && servicesCon4) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 首页")
            pageStatus.isServicesPage = true;
            break;
        }
    }

    // 判断是否为home页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为HOM页-textList "+ textList.length)
    let homeCon1 = false;
    let homeCon2 = false;
    let homeCon3 = false;
    let homeCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(VodafoneGhsPageTag.homePageTag1) !== -1) {
            homeCon1 = true;
        }
        else if (curText.indexOf(VodafoneGhsPageTag.homePageTag2) !== -1) {
            homeCon2 = true;
        }
        else if (curText.indexOf(VodafoneGhsPageTag.homePageTag3) !== -1) {
            homeCon3 = true;
        }
        else if (curText.indexOf(VodafoneGhsPageTag.homePageTag4) !== -1) {
            homeCon4 = true;
        }
    }
    if (homeCon1 && homeCon2 && homeCon3 && homeCon4) {
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 首页");
        pageStatus.isHomePage = true;
    }

    // 判断是否为 bill check confirm 页
    let billCheckConfirmCon1 = false;
    let billCheckConfirmCon2 = false;
    let billCheckConfirmCon3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.transactionAskPageTag1) !== -1) {
            billCheckConfirmCon1 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.transactionAskPageTag2) !== -1) {
            billCheckConfirmCon2 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.transactionAskPageTag3) !== -1) {
            billCheckConfirmCon3 = true
        }

        if (billCheckConfirmCon1 && billCheckConfirmCon2 && billCheckConfirmCon3) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 bill check confirm 页")
            pageStatus.isBillCheckConfirmPage = true;
            break;
        }
    }

    // 释放缓存
    textList.length = 0;
    textList = null;

    editList.length = 0;
    editList = null;

    return pageStatus;
};

// 是否为 登录页
const isLoginPage = () => {
    let textList = className("TextView").find();

    // console.log(Constant.UI_SDK_VERSION + "判断是否为登录页-textList "+ textList.length)
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(VodafoneGhsPageTag.loginPageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginPage-当前是登录页")
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    let editList = className("EditText").find();
    // console.log(Constant.UI_SDK_VERSION + "判断是否为登录页-editList "+  editList.length)
    for (let index = 0; index < editList.length; index++) {
        let tv = editList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(VodafoneGhsPageTag.loginPageTag1) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginPage-当前是登录页");
            editList.length = 0;
            editList = null;
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    editList.length = 0;
    editList = null;
    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isLoginPage-当前不是登录页")
    return false;
}

// 监听是否打开了 登录-pin页
const doOpenLoginPinPage = () => {
    // 循环判断是否为 登录-pin页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 登录-pin页
        if (isLoginPinPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 登录-pin页
const isLoginPinPage = () => {
    let textList = className("TextView").find();

    // console.log(Constant.UI_SDK_VERSION + "判断是否为PIN页-editList "+ editList.length)
    let pinCon1 = false;
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.pinPageTag1) !== -1) {
            pinCon1 = true;
            break;
        }
    }

    if (pinCon1) {
        console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-当前是登录-pin页");
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;

    console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-当前不是登录-pin页")
    return false;
}

// 监听是否打开了 服务页
const doOpenServicesPage = () => {
    // 循环判断是否为 服务页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 Send Money 页
        if (isServicesPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 服务页
const isServicesPage = () => {
    let textList = className("TextView").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;
    let findTag4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "isServicesPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.servicesPageTag1) !== -1) {
            findTag1 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.servicesPageTag2) !== -1) {
            findTag2 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.servicesPageTag3) !== -1) {
            findTag3 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.servicesPageTag4) !== -1) {
            findTag4 = true
        }
    }

    if (findTag1 && findTag2 && findTag3 && findTag4) {
        console.log(Constant.UI_SDK_VERSION + "isServicesPage-当前是 首页")
        textList.length = 0;
        textList = null;

        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isServicesPage-当前不是 首页")
    return false;
}

// 监听是否打开了 首页
const doOpenHomePage = () => {
    // 循环判断是否为 首页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 Send Money 页
        if (isHomePage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为首页
const isHomePage = () => {
    let textList = className("TextView").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;
    let findTag4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(VodafoneGhsPageTag.homePageTag1) !== -1) {
            findTag1 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.homePageTag2) !== -1) {
            findTag2 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.homePageTag3) !== -1) {
            findTag3 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.homePageTag4) !== -1) {
            findTag4 = true
        }
    }

    if (findTag1 && findTag2 && findTag3 && findTag4) {
        console.log(Constant.UI_SDK_VERSION + "isHomePage-当前是 首页")
        textList.length = 0;
        textList = null;

        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isHomePage-当前不是 首页")
    return false;
}

// 监听是否打开了 流水查看确认页
const doOpenBillCheckConfirmPage = () => {
    // 循环判断是否为 流水查看确认页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 流水查看确认页
        if (isBillCheckConfirmPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};


// 是否为 流水查看确认页
const isBillCheckConfirmPage = () => {
    let textList = className("TextView").find();

    // 先判断是否出现服务器错误提示
    // let serErrCon1 = false;
    // for (let index = 0; index < textList.length; index++) {
    //     let tv = textList[index];
    //     let curText = tv.text() || ""
    //     // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

    //     if (curText.indexOf(VodafoneGhsPageTag.networkErrAlterTag1) !== -1) {
    //         console.log(Constant.UI_SDK_VERSION + "isBillCheckConfirmPage-当前出现服务器错误提示.")
    //         serErrCon1 = true;
    //         break;
    //     }
    // }
    // if (serErrCon1) {
    //     click(VodafoneGhsPageTag.networkErrAlterTag2);
    //     sleep(500);
    //     click(VodafoneGhsPageTag.networkErrAlterTag2);
    //     sleep(1000);
    //     textList.length = 0;
    //     textList = null;
    //     textList = className("TextView").find();
    // }

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "isBillCheckConfirmPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.transactionAskPageTag1) !== -1) {
            findTag1 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.transactionAskPageTag2) !== -1) {
            findTag2 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.transactionAskPageTag3) !== -1) {
            findTag3 = true
        }
    }

    if (findTag1 && findTag2 && findTag3) {
        console.log(Constant.UI_SDK_VERSION + "isBillCheckConfirmPage-当前是 bill check confirm 页")
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isBillCheckConfirmPage-当前不是 bill check confirm 页")
    return false;
}

// 监听是否打开了 流水页
const doOpenBillListPage = () => {
    // 循环判断是否为 流水页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 流水页
        if (isBillListPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 bill list 页
const isBillListPage = () => {
    let textList = className("TextView").find();

    // 先判断是否出现服务器错误提示
    // let serErrCon1 = false;
    // for (let index = 0; index < textList.length; index++) {
    //     let tv = textList[index];
    //     let curText = tv.text() || ""
    //     // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

    //     if (curText.indexOf(VodafoneGhsPageTag.networkErrAlterTag1) !== -1) {
    //         console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前出现服务器错误提示.")
    //         serErrCon1 = true;
    //         break;
    //     }
    // }
    // if (serErrCon1) {
    //     click(VodafoneGhsPageTag.networkErrAlterTag2);
    //     sleep(500);
    //     click(VodafoneGhsPageTag.networkErrAlterTag2);
    //     sleep(1000);
    //     textList.length = 0;
    //     textList = null;
    //     textList = className("TextView").find();
    // }

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;
    let findTag4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前: " + index + ", 内容: " + curText)

        // 日期
        if (BaseStringUtil.isDigitAndLineStartOnly(curText)) {
            findTag1 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.transactionListItemTagStatus) !== -1) {
            findTag2 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.transactionListItemTagCharge) !== -1) {
            findTag3 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.transactionListItemTagTransactionID) !== -1) {
            findTag4 = true
        }

        if (findTag1 && findTag2 && findTag3 && findTag4) {
            break;
        }
    }

    if (findTag1 && findTag2 && findTag3 && findTag4) {
        console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前是 transaction list 页")
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前不是 transaction list 页")
    return false;
}

// 监听是否打开了 流水页
const doOpenPrincipalBillListPage = () => {
    // 循环判断是否为 流水页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 流水页
        if (isPrincipalBillListPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};


// 是否为 bill list 页
const isPrincipalBillListPage = () => {
    let textList = className("TextView").find();

    // 先判断是否出现服务器错误提示
    // let serErrCon1 = false;
    // for (let index = 0; index < textList.length; index++) {
    //     let tv = textList[index];
    //     let curText = tv.text() || ""
    //     // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

    //     if (curText.indexOf(VodafoneGhsPageTag.networkErrAlterTag1) !== -1) {
    //         console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前出现服务器错误提示.")
    //         serErrCon1 = true;
    //         break;
    //     }
    // }
    // if (serErrCon1) {
    //     click(VodafoneGhsPageTag.networkErrAlterTag2);
    //     sleep(500);
    //     click(VodafoneGhsPageTag.networkErrAlterTag2);
    //     sleep(1000);
    //     textList.length = 0;
    //     textList = null;
    //     textList = className("TextView").find();
    // }

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "isPrincipalBillListPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.transactionListPageTag1) !== -1) {
            findTag1 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.transactionListPageTag2) !== -1) {
            findTag2 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.transactionListPageTag3) !== -1) {
            findTag3 = true
        }
    }

    if (findTag1 && findTag2 && findTag3) {
        console.log(Constant.UI_SDK_VERSION + "isPrincipalBillListPage-当前是 transaction list 页")
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isPrincipalBillListPage-当前不是 transaction list 页")
    return false;
}

// 监听是否打开了 send money 页
const doOpenSendMoneyPage = () => {
    // 循环判断是否为 流水页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 send money页
        if (isSendMoneyPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money 页
const isSendMoneyPage = () => {
    let textList = className("TextView").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;
    let findTag4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(VodafoneGhsPageTag.sendMoneyPageTag2) !== -1) {
            findTag1 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.sendMoneyPageTag3) !== -1) {
            findTag2 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.sendMoneyPageTag4) !== -1) {
            findTag3 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.sendMoneyPageTag5) !== -1) {
            findTag4 = true
        }

        if (findTag1 && findTag2 && findTag3 && findTag4) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前是 Send Money 页")
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前不是 Send Money 页")
    return false;
}

// 监听是否打开了 Send Money input account 页
const doOpenInputTargetAccountPage = () => {
    // 循环判断是否为 Send Money input account 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 Send Money input account 页
        if (isInputTargetAccountPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money input account 页
const isInputTargetAccountPage = () => {
    // let textList = className("TextView").find();
    let editList = className("EditText").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;

    if(editList.length===3){
        findTag1 = true;        
        findTag2 = true;
        findTag3 = true;
    }

    // for (let index = 0; index < textList.length; index++) {
    //     let tv = textList[index];
    //     let curText = tv.text() || ""
    //     // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

    //     if (curText.indexOf(VodafoneGhsPageTag.sendMoneyMtnPageTag1) !== -1) {
    //         findTag1 = true
    //         break;
    //     }
    // }
    // for (let index = 0; index < editList.length; index++) {
    //     let tv = editList[index];
    //     let curText = tv.text() || "";
    //     console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText);

    //     if (curText.indexOf(VodafoneGhsPageTag.sendMoneyAccountInputPageTag1) !== -1) {
    //         findTag1 = true;
    //     }
    //     if (curText.indexOf(VodafoneGhsPageTag.sendMoneyAccountInputPageTag2) !== -1) {
    //         findTag2 = true;
    //     }
    //     if (curText.indexOf(VodafoneGhsPageTag.sendMoneyAccountInputPageTag3) !== -1) {
    //         findTag3 = true;
    //     }
    // }

    if (findTag1 && findTag2 && findTag3) {
        console.log(Constant.UI_SDK_VERSION + "isInputTargetAccountPage-当前是 Send Money input account 页")
        // textList.length = 0;
        // textList = null;
        editList.length = 0;
        editList = null;
        return true;
    }

    // textList.length = 0;
    // textList = null;
    editList.length = 0;
    editList = null;
    console.log(Constant.UI_SDK_VERSION + "isInputTargetAccountPage-当前不是 Send Money input account 页")
    return false;
}

// 监听是否打开了 Send Money Confirm 页
const doOpenSendMoneyConfirmPage = () => {
    // 循环判断是否为 Send Money Confirm 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 Send Money Confirm 页
        if (isSendMoneyConfirmPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money confirm 页
const isSendMoneyConfirmPage = () => {
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-开始判断 是否为 Send Money confirm 页")
    let textList = className("TextView").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;
    let findTag4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.sendMoneyConfirmPageTag1) !== -1) {
            findTag1 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.sendMoneyConfirmPageTag2) !== -1) {
            findTag2 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.sendMoneyConfirmPageTag3) !== -1) {
            findTag3 = true
        }
        else if (curText.indexOf(VodafoneGhsPageTag.sendMoneyConfirmPageTag4) !== -1) {
            findTag4 = true
        }

        if (findTag1 && findTag2 && findTag3 && findTag4) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前是 Send Money confirm 页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前不是 Send Money confirm 页")
    return false;
}

// 监听是否打开了 Send Money password 页
const doOpenSendMoneyPasswordPage = () => {
    // 循环判断是否为 Send Money password 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 Send Money password 页
        if (isSendMoneyPasswordPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money password 页
const isSendMoneyPasswordPage = () => {
    let textList = className("TextView").find();

    // console.log(Constant.UI_SDK_VERSION + "判断是否为PIN页-editList "+ editList.length)
    let pinCon1 = false;
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.pinPageTag1) !== -1) {
            pinCon1 = true;
            break;
        }
    }

    if (pinCon1) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前是登录-pin页");
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;

    console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前不是登录-pin页")
    return false;
}

// 监听是否打开了转账预校验页，通常是检验失败页
const doOpenSendMoneyPreCheckPage = () => {
    // 结果集合
    let sendResult = {
        isSuccess: false,
        isFail: false
    };
    // 循环判断是否为 Send Money Result 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // 确认进入了 Send Money Success 页
        if (isSendMoneyConfirmPage()) {
            sendResult.isSuccess = true;
            sendResult.isFail = false;
            break;
        }

        // 确认进入了 Send Money Fail 页
        if (isSendMoneyFailPage()) {
            sendResult.isSuccess = false;
            sendResult.isFail = true;
            break;
        }

        sleep(1 * 1000);
    }

    return sendResult;
};

// 监听是否打开了 Send Money Result 页
const doOpenSendMoneyResultPage = () => {
    // 结果集合
    let sendResult = {
        isSuccess: false,
        isFail: false
    };
    // 循环判断是否为 Send Money Result 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
           SmsUtil.syncSmsData(false, Constant.WALLET_VODAFONE_GHS_MNO);
        }

        // let textList = className("TextView").find();
        // // 先判断是否出现类似交易提示
        // let sameTransactionCon1 = false;
        // for (let index = 0; index < textList.length; index++) {
        //     let tv = textList[index];
        //     let curText = tv.text() || ""
        //     // console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前: " + index + ", 内容: " + curText)

        //     if (curText.indexOf(VodafoneGhsPageTag.sameTransferAlterTag1) !== -1) {
        //         console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前出现类似交易提示.")
        //         sameTransactionCon1 = true;
        //         break;
        //     }
        // }
        // if (sameTransactionCon1) {
        //     click(VodafoneGhsPageTag.sameTransferAlterTag3);
        //     sleep(500);
        //     click(VodafoneGhsPageTag.sameTransferAlterTag3);
        //     sleep(1000);
        // }
        // textList.length = 0;
        // textList = null;

        // 确认进入了 Send Money Success 页
        if (isSendMoneySuccessPage()) {
            sendResult.isSuccess = true;
            sendResult.isFail = false;
            break;
        }

        // 确认进入了 Send Money Fail 页
        if (isSendMoneyFailPage()) {
            sendResult.isSuccess = false;
            sendResult.isFail = true;
            break;
        }

        sleep(1 * 1000);
    }

    return sendResult;
};

// 是否为 Send Money Success 页
const isSendMoneySuccessPage = () => {
    let textList = className("TextView").find();

    // 先判断是否出现服务器错误提示
    // let serErrCon1 = false;
    // for (let index = 0; index < textList.length; index++) {
    //     let tv = textList[index];
    //     let curText = tv.text() || ""
    //     // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

    //     if (curText.indexOf(VodafoneGhsPageTag.networkErrAlterTag1) !== -1) {
    //         console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前出现服务器错误提示.")
    //         serErrCon1 = true;
    //         break;
    //     }
    // }
    // if (serErrCon1) {
    //     click(VodafoneGhsPageTag.networkErrAlterTag2);
    //     sleep(500);
    //     click(VodafoneGhsPageTag.networkErrAlterTag2);
    //     sleep(1000);
    //     textList.length = 0;
    //     textList = null;
    //     textList = className("TextView").find();
    // }

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(VodafoneGhsPageTag.sendMoneySuccessPageTag1) !== -1) {
            findTag1 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.sendMoneySuccessPageTag2) !== -1) {
            findTag2 = true
        }
        if (curText.indexOf(VodafoneGhsPageTag.sendMoneySuccessPageTag3) !== -1) {
            findTag3 = true
        }
    }

    if (findTag1 && findTag2 && findTag3) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前是 Send Money Success 页");
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前不是 Send Money Success 页")
    return false;
}

// 监听是否打开了 Send Money Mtn Fail 页
const doOpenSendMoneyMtnFailPage = () => {
    // 停留2秒缓冲
    sleep(2000);

    // 循环判断是否为 Send Money Mtn Fail 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryTransferFailCount; rIndex++) {
        // 确认进入了 Send Money Mtn Fail 页
        if (isSendMoneyFailPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money Fail 页
const isSendMoneyFailPage = () => {
    let textList = className("TextView").find();

    let findTag1 = false;
    // let findTag2 = false;
    // let findTag3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(VodafoneGhsPageTag.sendMoneyFailPageTag1) !== -1) {
            findTag1 = true;
            break;
        }
    }

    if (findTag1) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyFailPage-当前是 Send Money Fail 页");
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyFailPage-当前不是 Send Money Mtn Fail 页");
    return false;
}

// 是否为 月份字符串
const isMonthScaleWords = (word) => {
    if (word) {
        if (word.startsWith("Jan")) {
            return true;
        }
        if (word.startsWith("Feb")) {
            return true;
        }
        if (word.startsWith("Mar")) {
            return true;
        }
        if (word.startsWith("Apr")) {
            return true;
        }
        if (word.startsWith("May")) {
            return true;
        }
        if (word.startsWith("Jun")) {
            return true;
        }
        if (word.startsWith("Jul")) {
            return true;
        }
        if (word.startsWith("Aug")) {
            return true;
        }
        if (word.startsWith("Sep")) {
            return true;
        }
        if (word.startsWith("Oct")) {
            return true;
        }
        if (word.startsWith("Nov")) {
            return true;
        }
        if (word.startsWith("Dec")) {
            return true;
        }
    }
    return false;
};


module.exports = {
    doCheckPageStatus: doCheckPageStatus,
    isLoginPage: isLoginPage,
    doOpenLoginPinPage: doOpenLoginPinPage,
    isLoginPinPage: isLoginPinPage,
    doOpenServicesPage: doOpenServicesPage,
    isServicesPage: isServicesPage,
    doOpenHomePage: doOpenHomePage,
    isHomePage: isHomePage,

    doOpenBillCheckConfirmPage: doOpenBillCheckConfirmPage,
    isBillCheckConfirmPage: isBillCheckConfirmPage,
    doOpenBillListPage: doOpenBillListPage,
    isBillListPage: isBillListPage,
    doOpenPrincipalBillListPage: doOpenPrincipalBillListPage,
    isPrincipalBillListPage: isPrincipalBillListPage,
    doOpenSendMoneyPage:doOpenSendMoneyPage,
    isSendMoneyPage: isSendMoneyPage,
    doOpenInputTargetAccountPage: doOpenInputTargetAccountPage,
    isInputTargetAccountPage: isInputTargetAccountPage,

    doOpenSendMoneyConfirmPage: doOpenSendMoneyConfirmPage,
    doOpenSendMoneyPasswordPage: doOpenSendMoneyPasswordPage,
    isSendMoneyPasswordPage: isSendMoneyPasswordPage,
    doOpenSendMoneyResultPage: doOpenSendMoneyResultPage,

    doOpenSendMoneyPreCheckPage: doOpenSendMoneyPreCheckPage,
    isSendMoneyConfirmPage: isSendMoneyConfirmPage,
    isSendMoneyMtnSuccessPage: isSendMoneySuccessPage,
    doOpenSendMoneyMtnFailPage: doOpenSendMoneyMtnFailPage,
    isSendMoneyMtnFailPage: isSendMoneyFailPage,
    isMonthScaleWords: isMonthScaleWords
};